home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* */
- /* Application: QuickDraw™ FX */
- /* */
- /* Description: */
- /* */
- /* File: events.c */
- /* */
- /* Files: FX.π */
- /* FX.π.rsrc */
- /* FX.h */
- /* events.c */
- /* main.c */
- /* menu.c */
- /* */
- /* Programmer: Edgar Lee */
- /* Organization: Apple Computer, Inc. ©1992 */
- /* Department: Developer Technical Support, DTS */
- /* Language: C (Think C version 5.0.2) */
- /* Date Created: 5-26-92 */
- /* */
- /****************************************************************************/
-
- #include "FX.h"
-
- void handleMouseDown();
-
- void eventLoop()
- {
- EventRecord event;
- WindowPtr window;
- short clickArea;
- Rect screenRect;
- long sleep = 30;
- Point point;
-
- for (;;)
- {
- if (WaitNextEvent( everyEvent, &event, sleep, (RgnHandle)nil ))
- {
- if (event.what == mouseDown)
- {
- clickArea = FindWindow( event.where, &window );
-
- if (clickArea == inDrag)
- {
- screenRect = (**GetGrayRgn()).rgnBBox;
- DragWindow(window, event.where, &screenRect );
- }
- else if (clickArea == inGoAway)
- {
- if (TrackGoAway( window , event.where ))
- ExitToShell();
- }
- else if (clickArea == inMenuBar)
- {
- adjustMenus();
- handleMenu( MenuSelect( event.where ) );
- }
- else if (clickArea == inContent)
- {
- if (window != FrontWindow())
- SelectWindow( window );
- else
- {
- point = event.where;
- GlobalToLocal( &point );
- handleMouseDown( point );
- }
- }
- }
- else if (event.what == updateEvt)
- {
- window = (WindowPtr)event.message;
- SetPort( window );
-
- BeginUpdate( window );
- updateWindow();
- EndUpdate( window );
- }
- else if (event.what == keyDown || event.what == autoKey)
- {
- if ((event.modifiers & cmdKey) != 0)
- {
- adjustMenus();
- handleMenu( MenuKey( (char)(event.message & charCodeMask) ) );
- }
- }
- }
- }
- }
-
- void handleMouseDown( point )
- Point point;
- {
- int i;
- long ticks;
- int itemNum = -1;
-
- for (i = 0; i < numBItems; i++)
- if (PtInRect( point, &bItem[i].rect ))
- {
- if (i == settings.bItem - 1)
- return;
-
- drawItem( bItem[settings.bItem - 1].rect.left, bItem[settings.bItem - 1].rect.top,
- &bItem[settings.bItem - 1].label, true, false );
- drawItem( bItem[i].rect.left, bItem[i].rect.top,
- &bItem[i].label, true, true );
-
- itemNum = 0;
- settings.bItem = i + 1;
- break;
- }
-
- if (gCurrentExample / 10 == transferID || gCurrentExample / 10 == customID)
- for (i = 0; i < numTItems && itemNum == -1; i++)
- if (PtInRect( point, &tItem[i].rect ))
- {
- if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID)
- {
- drawItem( tItem[settings.tItem - 1].rect.left, tItem[settings.tItem - 1].rect.top,
- &tItem[settings.tItem - 1].label, true, false );
- drawItem( tItem[i].rect.left, tItem[i].rect.top,
- &tItem[i].label, true, true );
-
- itemNum = i + 1;
- settings.tItem = itemNum;
- }
- break;
- }
-
- if (gCurrentExample / 10 == arithmeticID || gCurrentExample / 10 == customID)
- for (i = 0; i < numAItems && itemNum == -1; i++)
- if (PtInRect( point, &aItem[i].rect ))
- {
- if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID)
- {
- drawItem( aItem[settings.aItem - 1].rect.left, aItem[settings.aItem - 1].rect.top,
- &aItem[settings.aItem - 1].label, true, false );
- drawItem( aItem[i].rect.left, aItem[i].rect.top,
- &aItem[i].label, true, true );
-
- itemNum = i + 1;
- settings.aItem = itemNum;
- }
- break;
- }
-
- if (gCurrentExample / 10 == colorizationID || gCurrentExample / 10 == customID)
- for (i = 0; i < numCItems && itemNum == -1; i++)
- if (PtInRect( point, &cItem[i].rect ))
- {
- if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID)
- {
- drawItem( cItem[settings.cItem - 1].rect.left, cItem[settings.cItem - 1].rect.top,
- &cItem[settings.cItem - 1].label, true, false );
- drawItem( cItem[i].rect.left, cItem[i].rect.top,
- &cItem[i].label, true, true );
-
- itemNum = i + 1;
- settings.cItem = itemNum;
- }
- break;
- }
-
- if (gCurrentExample / 10 == ditherID || gCurrentExample / 10 == customID)
- for (i = 0; i < numDItems && itemNum == -1; i++)
- if (PtInRect( point, &dItem[i].rect ))
- {
- if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID)
- {
- drawItem( dItem[settings.dItem - 1].rect.left, dItem[settings.dItem - 1].rect.top,
- &dItem[settings.dItem - 1].label, true, false );
- drawItem( dItem[i].rect.left, dItem[i].rect.top,
- &dItem[i].label, true, true );
-
- itemNum = i + 1;
- settings.dItem = itemNum;
- }
- break;
- }
-
- if (gCurrentExample / 10 == searchProcID || gCurrentExample / 10 == customID)
- for (i = 0; i < numMItems && itemNum == -1; i++)
- if (PtInRect( point, &mItem[i].rect ))
- {
- if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID)
- {
- drawItem( mItem[settings.mItem - 1].rect.left, mItem[settings.mItem - 1].rect.top,
- &mItem[settings.mItem - 1].label, true, false );
- drawItem( mItem[i].rect.left, mItem[i].rect.top,
- &mItem[i].label, true, true );
-
- itemNum = i + 1;
- settings.mItem = itemNum;
- }
- break;
- }
-
- if (gCurrentExample / 10 == paintBucketID)
- {
- Rect rect;
- void paintBucketExample();
-
- SetRect( &rect, (*gWindow).portRect.right - (*gGWorld).portRect.right - 20, 37,
- (*gWindow).portRect.right - 20, 37 + (*gGWorld).portRect.bottom );
-
- paintBucketExample( &rect, 0, point );
- }
- /*
- if (gCurrentExample / 10 == lassoID)
- {
- Rect rect;
- Rect frame;
- void lassoToolExample();
-
- frame.left = point.h;
- frame.top = point.v;
-
- while( StillDown() )
- {
- GetMouse( &point );
- frame.right = point.h;
- frame.bottom = point.v;
- }
-
- SetRect( &rect, (*gWindow).portRect.right - (*gGWorld).portRect.right - 20, 37,
- (*gWindow).portRect.right - 20, 37 + (*gGWorld).portRect.bottom );
-
- lassoToolExample( &rect, 0, &frame );
- }
- */
- if (itemNum != -1)
- {
- if (itemNum == 0)
- {
- drawSourceImage();
- ticks = drawFXImage();
- drawTime( ticks );
- }
- else
- {
- if (gCurrentExample / 10 == customID)
- itemNum = gCurrentExample;
- else
- itemNum = ((gCurrentExample / 10) * 10) + itemNum;
-
- if (itemNum != gCurrentExample || itemNum / 10 == customID)
- {
- gCurrentExample = itemNum;
-
- drawSourceImage();
- ticks = drawFXImage();
- drawTime( ticks );
- }
- }
- }
- }